package com.myworkspace.standard.web.dao;

import com.myworkspace.standard.common.IdWorker;
import com.myworkspace.standard.common.base.BaseDao;
import com.myworkspace.standard.web.model.OsFile;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Repository
public class IndexDao {
    @Resource
    private JdbcTemplate jdbcTemplate;
    @Resource
    private BaseDao baseDao;

    public List<OsFile> getFiles() throws Exception{
        String sql = "select * from os_file ";
        return  baseDao.queryForModel(sql,OsFile.class);
    }


    public Integer saveOsFile(OsFile osFile){
        osFile.setId(IdWorker.getId());
        String insertSql = "insert into os_file (`id`,`file_name`,`file_path`,`upload_time`,`file_size`,`file_url`) values (?,?,?,?,?,?)";

        return jdbcTemplate.update(insertSql, osFile.getId(), osFile.getFileName(), osFile.getFilePath(), osFile.getUploadTime(), osFile.getFileSize(),osFile.getFileUrl());
    }

    public void update(Long id){
        String sql  =  "update os_file set file_name='1' where id=?";
        jdbcTemplate.update(sql,id);
    }


    public List<Map<String, Object>> getFileList() {
        String sql = "select * from os_file ";
        return jdbcTemplate.queryForList(sql);
    }
}
